package com.demo.service.his;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 诊断结果
 * @author K
 */
@Slf4j
@Component
public class DiagnosisService {

    BigDecimal normalTemperature = BigDecimal.valueOf(37);

    public void exec(DelegateExecution execution) {
        BigDecimal temperature = execution.getVariable("temperature", BigDecimal.class);


        if (temperature.compareTo(normalTemperature) <= 0) {
            log.info("当前体温：{}，体温<=37°，流行感冒", temperature);
            execution.setVariable("diagnosis", "流行感冒");
            return;
        }

        String testing = execution.getVariable("result", String.class);
        if (StringUtils.equals("阳性", testing)) {
            log.info("当前体温：{}，核算检查结果是阳性", temperature);
            execution.setVariable("diagnosis", "新冠");
        } else {
            log.info("当前体温：{}，核算检查结果是阴性", temperature);
            execution.setVariable("diagnosis", "流行感冒");
        }
    }
}
